package com.link.base.tencent.corpwx.usertag.controller;

import com.link.base.tencent.corpwx.usertag.model.UserTag;
import com.link.base.tencent.corpwx.usertag.service.UserTagService;
import com.link.core.basic.annotations.JsonParam;
import com.link.core.basic.controller.BasicController;
import com.link.core.basic.service.BasicService;
import com.link.core.cllog.LCLogger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.HashMap;
import java.util.Map;

/**
 * 成员标签 
 *
 * @author 欧阳振强
 * @date 2020-01-06 10:35:58.0
 */
@Controller
@RequestMapping("/link/corpwx/userTag")
public class UserTagController extends BasicController<UserTag> {

    @Resource
    private UserTagService userTagService;

    @Override
    public BasicService<UserTag> getBasicService() throws Exception {
        return userTagService;
    }

    /**
     * 从企业微信获取成员标签信息同步到CRM
     *
     * @author 欧阳振强
     * @date 2020/01/06
     */
    @PostMapping(value = "/syncAllUserTagFromWx", name = "从企业微信获取成员标签信息同步到CRM")
    @ResponseBody
    public Map<String, Object> syncAllUserTagFromWx(HttpSession session, HttpServletRequest request) {
        Map<String, Object> result = new HashMap<String, Object>(4);
        try {
            userTagService.syncAllUserTagFromWx();
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }

    /**
     * 同步成员标签到企业微信
     *
     * @author 欧阳振强
     * @date 2020/01/06
     */
    @PostMapping(value = "/syncSingleUserTagToWx", name = "同步成员标签到企业微信")
    @ResponseBody
    public Map<String, Object> syncSingleUserTagToWx(@JsonParam UserTag userTag, HttpSession session, HttpServletRequest request) {
        Map<String, Object> result = new HashMap<String, Object>(4);
        try {
            userTagService.syncSingleUserTagToWx(userTag);
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }

    /**
     * 删除成员标签
     *
     * @author 欧阳振强
     * @date 2020/01/06
     */
    @PostMapping(value = "/deleteUserTag", name = "删除成员标签")
    @ResponseBody
    public Map<String, Object> deleteUserTag(@JsonParam UserTag userTag, HttpSession session, HttpServletRequest request) {
        Map<String, Object> result = new HashMap<String, Object>(4);
        try {
            userTagService.deleteUserTag(userTag);
            result.put("success", true);
        } catch (Exception e) {
            LCLogger.withException(e);
            result.put("success", false);
            result.put("result", e.getMessage());
        }
        return result;
    }
}